package Ventanas.usuario;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;

import javax.swing.*;

import util.GetFrame;

public class PanelPsw extends JPanel implements ActionListener{
	
	private JButton bEnviar;/**/
	private JLabel lpsw;
	private JPasswordField tpsw;
	private JLabel fondo;

	public PanelPsw() {
		
		lpsw = new JLabel();
		tpsw = new JPasswordField();
		bEnviar = new JButton();
		fondo = new JLabel();

		setLayout(null);
		
		this.setBackground(new Color(3, 41, 51));

		lpsw.setText("Password");
		add(lpsw);
		lpsw.setBounds(195, 260, 90, 25);
		lpsw.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
		lpsw.setForeground(new java.awt.Color(255, 255, 255));

		bEnviar.setText("Enviar");
		bEnviar.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
		bEnviar.addActionListener(this);
		add(bEnviar);
		bEnviar.setBounds(540, 260, 90, 30);
		
		add(tpsw);
		tpsw.setBounds(312, 260, 210, 30);
		tpsw.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
		tpsw.setText("12345");
		tpsw.setForeground(new java.awt.Color(255, 255, 255));
		tpsw.setBackground(new Color(6, 52, 72));
		tpsw.setForeground(new java.awt.Color(255, 255, 255));

		fondo.setIcon(new ImageIcon("src/resources/onda.png"));
		add(fondo);
		fondo.setBounds(155, 10, 516, 290);
		
	}// </editor-fold>


	@Override
	public void actionPerformed(ActionEvent e) {
		
		if(e.getSource()==bEnviar)
		{
			Ventana ventana = GetFrame.getVentana(this);
			ventana.escribir("CLAVE "+tpsw.getText()+'\n');
			String respuesta = ventana.leer();
			if(respuesta.contains("302"))
			{
				JOptionPane.showMessageDialog(null, respuesta, "Password correcto", JOptionPane.INFORMATION_MESSAGE);
				this.setVisible(false);
				PanelMenu panel = new PanelMenu();
				ventana.getContentPane().add(panel,0);
				panel.setVisible(true);
				
			}
			else if(respuesta.contains("502")||respuesta.contains("503"))
			{
				JOptionPane.showMessageDialog(null, respuesta, "Password Erroneo", JOptionPane.ERROR_MESSAGE);
				tpsw.setText("");
			}
			
			}
		}
		
	}
	

